#pragma once

#include "RBTree.h"

namespace TEST1
{
	template<class K, class V>
	class map
	{
	public:
		//typedef RBTreeIterator<pair<K, V>> iterator;
		struct GetNum;
		typedef typename RBTree<K, pair<const K, V>, GetNum>::iterator iterator;

		pair<iterator, bool> insert(const pair<K, V>& val)
		{
			return _tree.insert(val, getnum);
		}

		void inorder()
		{
			_tree.inOrder(getnum);
		}

		iterator begin()
		{
			return _tree.begin();
		}

		iterator end()
		{
			return _tree.end();
		}

		V& operator[] (const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}

	private:
		struct GetNum
		{
			const K& operator() (const pair<K, V>& p)
			{
				return p.first;
			}
		};

	private:
		RBTree<K, pair<const K, V>, GetNum> _tree;
		GetNum getnum;
	};

	//void Test1()
	//{
	//	int num[] = { 4, 1, 3, 7, 10, 9, 8 };
	//	map<int, int> hash;
	//	for (auto& i : num)
	//		hash.insert(make_pair(i, i));

	//	for (auto& i : hash)
	//	{
	//		cout << i.second << ' ';
	//		cout << ++(i.second) << endl;
	//	}	
 //	}
	void Test1()
	{
		map<string, int> countMap;
		const char* str[] = { "aaa", "aaa", "bbb", "ccc", "bbb", "ddd", "ccc" };
		for (auto& i : str)
		{
			countMap[i]++;
		}

		for (auto& e : countMap)
			cout << e.first << ":" << e.second << endl;
	}
}